package java_collection.lab;

import java.util.ArrayList;
import java.util.List;

public class ListSwap {

	public static void main(String[] args) {
		List <Integer> list = new ArrayList<>();
		list.add(10);
		list.add(20);
		list.add(30);
		list.add(40);
		System.out.println(list);
		
		System.out.println("Value at 0 index = " + list.get(0));
		System.out.println("Value at 1 index = " + list.get(1));
		System.out.println("Value at 2 index = " + list.get(2));
		
		swap(list,0,2);
		
		System.out.println(list);
		
		for (int i: list) {
			System.out.printf("%d ",i);
		}

	}
	
	public static <E> void swap(List<E> a, int i, int j) {
	    E tmp = a.get(i);
	    a.set(i, a.get(j));
	    a.set(j, tmp);
	}

}
